Data stored on a mass storage device such as a hard drive in a computer system may be accessed in a number of ways. One conventional method is to use read and write system calls through the operating system. However, system calls impose a relatively large delay that is often unacceptable in high performance software applications. Another conventional method is to use memory mapped files. This maps the file into the virtual address space for the software application. The file may then be accessed using a virtual memory address within the range corresponding to the memory mapped file. The virtual memory subsystem of the operating system can swap portions of the file between the mass storage device and memory as they are accessed. This effectively caches portions of the file in memory, which can be accessed much more quickly than typical mass storage devices. Thus, memory mapped files have several benefits, including avoiding the overhead of a system call and caching portions of the files in memory.
In most modern computer systems, memory is divided into blocks called pages. The virtual memory subsystem swaps pages between memory and a page file on the mass storage device. If a page is accessed by a software application and is not resident in memory, the virtual memory subsystem may copy the page from the mass storage device into memory, after freeing up space in memory for the page if necessary. Pages that remain resident in memory can subsequently be accessed rapidly without copying them from mass storage. The virtual memory subsystem sees memory usage for all processes in the computer system and can adjust per-process memory utilization. The virtual memory subsystem may attempt to optimize which pages are kept in memory and which are swapped out to mass storage, using a generic algorithm such as keeping the most recently used pages in memory and swapping out the least recently used. However, the virtual memory subsystem does not know what pages are most likely to be used in the future, sometimes resulting in removal of high priority pages and increased swapping or thrashing.
The Microsoft Windows® operating system does provide VirtualLock/VirtualUnlock system calls which enable an application to tell the virtual memory manager that a particular page should not be swapped out to disk. However, this approach is limited in that applications may only divide pages into locked pages which cannot be swapped out of memory, and unlocked pages which can.